﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using BMS.Entity.Dictionary;
using BMS.IService;
using BMS.DTO;

namespace ApiServer.Controllers.Dictionary
{
    /// <summary>
    /// 字典主表（目录）控制器
    /// </summary>
    [Route("key")]
    [ApiController]
    public class DictionaryKeyController : BaseController<DictionaryKey>
    {
        private readonly IDictionaryKeyService dictionaryKeyService;
        public DictionaryKeyController(IDictionaryKeyService dictionaryKeyService):base(dictionaryKeyService)
        {
            this.dictionaryKeyService= dictionaryKeyService;
        }
        /// <summary>
        /// 添加字典集
        /// </summary>
        /// <param name="dto">字典集</param>
        /// <returns></returns>
        [HttpPost]
        [ApiExplorerSettings(GroupName = "v1")]
        public async Task<IActionResult> InsertDictionaryList(DictionaryListFormDTO dto)
        {
            return Ok(await dictionaryKeyService.InsertDictionaryList(dto));
        }
        /// <summary>
        /// 修改字典集
        /// </summary>
        /// <param name="dto">字典集</param>
        /// <returns></returns>
        [HttpPut]
        [ApiExplorerSettings(GroupName = "v1")]
        public async Task<IActionResult> UpdateDictionaryList(DictionaryListFormDTO dto)
        {
            return Ok(await dictionaryKeyService.UpdateDictionaryList(dto));
        }
        /// <summary>
        /// 删除字典集，采用逻辑删除
        /// </summary>
        /// <param name="ids">字典键ID集合</param>
        /// <returns></returns>
        [HttpDelete]
        [ApiExplorerSettings(GroupName = "v1")]
        public async Task<IActionResult> SoftDeleteDictionaryList(string ids)
        {
            return Ok(await dictionaryKeyService.SoftDeleteDictionaryList(ids));
        }
        /// <summary>
        /// 查询字典键集合
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [ApiExplorerSettings(GroupName = "v1")]
        public async Task<IActionResult> SearchDictionaryKeys()
        {
            return Ok(await dictionaryKeyService.SearchDictionaryKeys());
        }
    }
}
